<template>
  <div class="check-con">
    <el-form ref="checkFormRef" :model="checkForm" :rules="rules" label-width="120px" class="demo-ruleForm"
      :size="formSize" status-icon>
      <el-form-item label="经办人审核意见" prop="approveDescription">
        <el-input style="width: 320px" v-model="checkForm.approveDescription" type="textarea"
          placeholder="请输入经办人审核意见" />
      </el-form-item>
      <el-form-item label="经办人签字" prop="approveDescription">
        <el-input style="width: 320px" v-model="checkForm.approveDescription" type="textarea" placeholder="请输入经办人签字" />
      </el-form-item>
    </el-form>
  </div>
  <div style="margin-top: 30px; text-align: center">
    <el-button type="plain" @click="toClose()">关闭</el-button>
    <el-button type="primary" @click="submitForm(checkFormRef)" :loading="saveLoad">提交意见 <i
        class="el-icon-arrow-right el-icon--right"></i></el-button>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, nextTick } from 'vue'
import { toCheck } from '@/api/yearCheck/index'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
const emit = defineEmits(['close'])

const props = defineProps({
  currentRow: {
    type: Object,
    default: {}
  }
})

const checkForm = reactive({
  approveDescription: '',
  approveStatus: '',
  approveLevel: props.currentRow.approveLevel == 2 ? '6' : '8',
  id: props.currentRow.id,
  r3: []
})
const checkFormRef = ref()
const saveLoad = ref(false)

const rules = reactive({
  approveStatus: [
    {
      required: true,
      trigger: 'blur',
      message: '请选择审核结果'
    }
  ]
})
const toClose = () => {
  emit('close')
}

const toCloseAll = () => {
  emit('saveSuccess')
}

const submitForm = async (formEl) => {
  await formEl.validate((valid, fields) => {
    if (valid) {
      saveLoad.value = true
      // const { id, approveLevel } = props.currentRow
      toCheck({ ...checkForm }).then(res => {
        ElMessage({
          message: '审核提交成功',
          type: 'success'
        })
        toCloseAll()
        saveLoad.value = false
      })
    } else {
      console.log('error submit!', fields)
    }
  })
}

</script>
<style scoped lang="scss">
.check-con {
  width: 100%;
  display: flex;
}
</style>
